<?php
namespace Home\Controller;
use Think\Controller;
class BaseController extends Controller {
   
 //一维数组
   static public $treeList = array(); //存放无限分类结果如果一页面有多个无限分类可以使用 Tree::$treeList = array(); 清空
    /**
     * 无限级分类
     * access public
     * @param Array $data        //数据库里获取的结果集
     * @param Int $pid
     * @param Int $count        //第几级分类
     * return Array $treeList
     */
    static public function tree(&$data,$fid = 0, $count = 1) {
        foreach ($data as $key => $value){
            if($value['fid']==$fid){
                $value['level'] = $count;
                //对标题进行格式化
                if($value['fid']==0){
                    $value['content'] = str_repeat('&nbsp;&nbsp;&nbsp;', ($count-1)).$value['content'];
                }else{
                      $value['content'] = str_repeat('&nbsp;&nbsp;&nbsp;', ($count+2)).$value['content'];  
                }
            
                self::$treeList [] = $value;
                unset($data[$key]);
                self::tree($data,$value['id'],$count + 1);
            } 
        }
        return self::$treeList ;
    }
}